package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.modles.CustomMapData;

/**
 * 轮播图的适配器
 * Created by lanouhn on 16/8/24.
 */
public class CustomMapAdapter extends StaticPagerAdapter {

//    //用于存轮播图二级页面Id
//    private SharedPreferences sp;
//    private SharedPreferences.Editor editor;


    private Context context;
    private CustomMapData customMapData;

    public CustomMapAdapter(Context context, CustomMapData customMapData) {
        this.context = context;
        this.customMapData = customMapData;
    }

    @Override
    public View getView(ViewGroup container, final int position) {
        ImageView view = new ImageView(container.getContext());
        Picasso.with(context).load(customMapData.getData().getBanner().get(position).getPhoto()).into(view);
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup
                .LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

//        sp = context.getSharedPreferences("config_custom", Context.MODE_PRIVATE);
//        editor = sp.edit();

        //跳转至，轮播图的二级页面
//        view.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//
//                String extend_ID = customMapData.getData().getBanner().get(position).getExtend();
//
//                String[] extend_IDArr = extend_ID.split(",");
//
//                String customMapTwo_ID = null;
//
//                for (int i = 0; i < extend_IDArr.length; i++) {
//                    String temp = extend_IDArr[i];
//                    if (i != extend_IDArr.length - 1) {
//                        temp = temp + "%2C";
//                    }
//                    customMapTwo_ID = customMapTwo_ID + temp;
//                }
//
//                Intent intent = new Intent(context, CustomMapTwoActivity.class);
////                editor.putString("customMapTwo_iD", customMapTwo_ID);
////                editor.commit();
//
//                intent.putExtra("customMapTwo_iD",customMapTwo_ID);
//
//                context.startActivity(intent);
//            }
//        });


        return view;
    }


    @Override
    public int getCount() {
        return customMapData.getData().getBanner().size();
    }
}
